// 枚举
fn main() {
    inspect(WebEvent::KeyPress('x'));
    inspect(WebEvent::Paste("my text".to_owned()));
    inspect(WebEvent::Click { x: 20, y: 30 });
    inspect(WebEvent::PageUnload);
    inspect(WebEvent::PageLoad);
    // type alias
    let add = LoogName::Add;
    println!("{:?}", add);
    println!("{:?}", LoogName::Subtract);
}
// 允许多种类型的枚举，常量标识｜元组｜结构体
enum WebEvent {
    PageLoad,
    PageUnload,
    KeyPress(char),
    Paste(String),
    Click { x: i64, y: i64 },
}
fn inspect(event: WebEvent) {
    match event {
        WebEvent::PageLoad => println!("page loaded!"),
        WebEvent::PageUnload => println!("page unloaded!"),
        WebEvent::Paste(s) => println!("pasted \"{}\"", s),
        WebEvent::KeyPress(c) => println!("pressed '{}'", c),
        WebEvent::Click { x, y } => {
            println!("clicked at x= {},y={}", x, y);
        }
    }
}
//  type alias,给长名字起别名
#[derive(Debug)]
enum LoooooooooooooooooNammmmmmmmme {
    Add,
    Subtract,
}
#[allow(dead_code)]
impl LoooooooooooooooooNammmmmmmmme {
    fn run(&self, x: i32, y: i32) -> i32 {
        match self {
            Self::Add => x + y,
            Self::Subtract => x - y,
        }
    }
}
type LoogName = LoooooooooooooooooNammmmmmmmme;
